from flask import Blueprint,request
from app.service.follow_service import FollowService
from utils.response_utils import ResponseUtils

follow = Blueprint('follow', __name__)

@follow.route('/follow_user', methods=['POST'])
def follow_user():
    try:
        result = FollowService.follow_user(request)
        return ResponseUtils.success(result)
    except Exception as e:
        return ResponseUtils.error(message=str(e), code=500)

@follow.route('/unfollow_user', methods=['POST'])
def unfollow_user():
    try:
        result = FollowService.unfollow_user(request)
        return ResponseUtils.success(result)
    except Exception as e:
        return ResponseUtils.error(message=str(e), code=500)
    
@follow.route('/get_following_list_by_user_id', methods=['POST'])
def get_following_list_by_user_id():
    try:
        get_following_list_by_user_id = FollowService.get_following_list_by_user_id(request=request)
        return ResponseUtils.success(data=get_following_list_by_user_id)
    except Exception as e:
        return ResponseUtils.error(message=str(e), code=500)
    

@follow.route('/is_follow', methods=['POST'])
def is_follow():
    try:
        is_follow = FollowService.is_follow(request=request)
        print('isfollow',is_follow['count'])
        if is_follow['count'] == 0:
            return ResponseUtils.success(data={'isFollowing':False})
        else:
            return ResponseUtils.success(data={'isFollowing':True})
    except Exception as e:
        return ResponseUtils.error(message=str(e), code=500)